import { Button, Space } from 'ant-design-vue'
import { actualStatusObj, backstageStatusObj, examineResultTypeObj, tableColumns } from './data'

export function useColumns(updateFunction: Function, detailFunction: Function) {
  const getColumns = (column, record) => {
    if (column.dataIndex === 'productName') {
      return <span>{record.productName}</span>
    } else if (column.dataIndex === 'productDate') {
      return <span>{record.productDate}</span>
    } else if (column.dataIndex === 'actualLocationName') {
      return <span>{record.actualLocationName}</span>
    } else if (column.dataIndex === 'actualLocationLastTime') {
      return <span>{record.actualLocationLastTime}</span>
    } else if (column.dataIndex === 'actualStatus') {
      let actualStatusSrt = ''
      actualStatusObj.forEach(model => {
        if (model.value == record.actualStatus) {
          actualStatusSrt = model.name
        }
      })
      return <span>{actualStatusSrt}</span>
    } else if (column.dataIndex === 'backstageName') {
      return <span>{record.backstageName}</span>
    } else if (column.dataIndex === 'backstageLastTime') {
      return <span>{record.backstageLastTime}</span>
    } else if (column.dataIndex === 'identityCode') {
      return <span>{record.identityCode}</span>
    } else if (column.dataIndex === 'packingCode') {
      return <span>{record.packingCode}</span>
    } else if (column.dataIndex === 'backstageStatus') {
      let backstageStatusSrt = ''
      backstageStatusObj.forEach(model => {
        if (model.value == record.actualStatus) {
          backstageStatusSrt = model.name
        }
      })
      return <span>{backstageStatusSrt}</span>
    } else if (column.key === 'action') {
      return (
        <Space>
          <Button
            type='link'
            onClick={() => detailFunction(record.code)}
            v-auth={['warehouse:sale-return-order:detail']}
          >
            详情
          </Button>
          <Button type='link' onClick={() => updateFunction(record.code)} v-auth={['warehouse:sale-return-order:edit']}>
            编辑
          </Button>
        </Space>
      )
    }
  }
  return {
    getColumns,
    tableColumns
  }
}
